
using System;
using System.Collections.Generic;

using Grr.Web;
using Grr.Models;

using Castle.MonoRail.Framework;
using Castle.MonoRail.Framework.Views.Aspx;

public partial class Views_Grurrah_person : GrurrahViewPage {

    private static readonly int MaxResults = 10;

    SearchResult created_result;
    SearchResult doing_result;
    SearchResult want_result;

    protected override string TabName
    {
        get { return "explore"; }
    }

    protected override void SetProperties ()
    {
        Person = (string) PropertyBag["Person"];
        created_result = (SearchResult) PropertyBag["Created"];
        doing_result = (SearchResult)PropertyBag["Doing"];
        want_result = (SearchResult)PropertyBag["WantToDo"];

        CreatedNextButton.Visible = Created.MoreMatchesAvailable;
    }

    public string Person
    {
        get {
            object o = ViewState["Person"];
            if (o == null)
                return String.Empty;
            return (string)o;
        }
        set
        {
            ViewState["Person"] = value;
        }
    }

    public int CurrentCreatedResultsIndex
    {
        get
        {
            object o = ViewState["CurrentCreatedResultsIndex"];
            if (o == null)
                return 0;
            return (int)o;
        }
        set
        {
            ViewState["CurrentCreatedResultsIndex"] = value;
        }
    }

    public int CurrentDoingResultsIndex
    {
        get
        {
            object o = ViewState["CurrentDoingResultsIndex"];
            if (o == null)
                return 0;
            return (int)o;
        }
        set
        {
            ViewState["CurrentDoingResultsIndex"] = value;
        }
    }

    public int CurrentWantToDoResultsIndex
    {
        get
        {
            object o = ViewState["CurrentWantToDoResultsIndex"];
            if (o == null)
                return 0;
            return (int)o;
        }
        set
        {
            ViewState["CurrentWantToDoResultsIndex"] = value;
        }
    }

    public SearchResult Created
    {
        get
        {
            if (created_result == null)
                return SearchResult.Empty;
            return created_result;
        }
    }

    public SearchResult Doing
    {
        get
        {
            if (doing_result == null)
                return SearchResult.Empty;
            return doing_result;
        }
    }

    public SearchResult WantToDo
    {
        get
        {
            if (want_result == null)
                return SearchResult.Empty;
            return want_result;
        }
    }
    protected void CreatedNextButton_Click(object sender, EventArgs e)
    {
        created_result = Grr.Models.Tag.GetGrurrahsForTag (Person, MaxResults, CurrentCreatedResultsIndex + MaxResults);
        CurrentCreatedResultsIndex += MaxResults;
        CreatedPanel.ForceAnUpdate();

        CreatedPrevButton.Visible = true;
        CreatedNextButton.Visible = Created.MoreMatchesAvailable;
    }
    protected void CreatedPrevButton_Click(object sender, EventArgs e)
    {
        created_result = Grr.Models.Tag.GetGrurrahsForTag (Person, MaxResults, CurrentCreatedResultsIndex - MaxResults);
        CurrentCreatedResultsIndex -= MaxResults;
        CreatedPanel.ForceAnUpdate();

        CreatedNextButton.Visible = true;
        CreatedPrevButton.Visible = CurrentCreatedResultsIndex != 0;
    }
}
